﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using ClassLibrary.App_Code;

/// <summary>
/// Summary description for Cart_itemDAL
/// </summary>
public class Cart_itemDAL
{
    public static ShopMobileDataContext data = new ShopMobileDataContext();
	public Cart_itemDAL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public static List<Cart_itemBLL> getCartItems(int cart_id)
    {
        var ds = from cart in data.Cart_items
                 where cart.cart_id == cart_id
                 select new Cart_itemBLL(cart.id, cart.add_on.Value, cart.cart_id.Value, cart.item_id.Value, cart.Item.name, cart.quantity.Value, cart.Item.price.Value, cart.cash_total.Value);
                     //Cart_itemBLL(cart.id, cart.add_on, cart.cart_id, cart.item_id, cart.Item.name, cart.Item.price,cart.Item.Category.name_cat, cart.quantity, cart.cash_total);
        return ds.ToList<Cart_itemBLL>();
    }
    public static int totalCount(DateTime f, DateTime t)
    {
        var car = from c in data.Cart_items
                  where c.add_on.Value.Date >= f.Date && c.add_on.Value.Date <= t.Date
                  select c.quantity;
        return car.Sum().Value;
    }
    public static string totalItemMax(DateTime f, DateTime t)
    {
        var car = (from c in data.Cart_items
                   where c.add_on.Value.Date >= f.Date && c.add_on.Value.Date <= t.Date
                   select c.Item.name).Max();
        return car.ToString();
    }
}